#ifndef __QUERYRESULT_HPP_
#define __QUERYRESULT_HPP_
//该头文件服务于关键字查询  保存查询结果
//同时定义查询结果的排序规则
#include "UTF8Code.hpp"
#include <string>

using std::string;

//查询结果类
class QueryResult {
public:
    QueryResult(string word, int freq, int dist)
        : _word(word), _freq(freq), _dist(dist){}

    string getWord() const {
        return _word;
    }

    int getFreq() const {
        return _freq;
    }

    int getDist() const {
        return _dist;
    }

    void setFreq(int freq) {
        _freq = freq;
    }

    void setDist(int dist) {
        _dist = dist;
    }

private:
    string _word;
    int _freq;
    int _dist;
};

//对查询结果排序的排序规则（函数对象形式）
struct Compare{
    bool operator()(const QueryResult &lhs, const QueryResult &rhs) {
        if (lhs.getDist() > rhs.getDist()) { //先比较编辑距离
            return true;
        } else if (lhs.getDist() == rhs.getDist()) {
            if (lhs.getFreq() < rhs.getFreq()) //再比较频率
                return true;
            else if (lhs.getFreq() == rhs.getFreq()) {
                if (lhs.getWord() > rhs.getWord()) //最后比较字母顺序
                    return true;
                else
                    return false;
            } else
                return false;
        } else
            return false;
    }
};

#endif
